package main

import (
	"fmt"
	"sync"
)

// 这个方法只负责写入，所以可以规范writeCh为只写
func writeFn(writeCh chan<- int) {
	defer wg.Done()
	for i := 0; i < 10; i++ {
		fmt.Printf("【写入】：%v\n", i)
		writeCh <- i
	}
	close(writeCh)
}

// 这个方法只负责读取，可以规范readCh为只读
func readFn(readCh <-chan int) {
	defer wg.Done()
	for num := range readCh {
		fmt.Printf("【打印】：%v\n", num)
	}
}

var wg sync.WaitGroup

func main() {
	var ch = make(chan int)
	wg.Add(1)
	go writeFn(ch)
	wg.Add(1)
	go readFn(ch)
	wg.Wait()
	println("main exit")
}
